'use strict';

angular.module('myApp.classes_detail', [])

.controller('classes_detailCtrl', ['$scope','$routeParams','$http',
    
    function($scope,$routeParams,$http,$location) {

        $http.get('v1/classes/'+ $routeParams.id).success(function(data){

            $scope.classe = data['result'][0];

        });

        //班级 学校 老师
        $http.get('v1/classes').success(function(data){
            $scope.model = data.result['data'];
             // console.log($scope.model);
        });
        $http.get('v1/school').success(function(data){
            $scope.nodel = data.result['data'];
             // console.log($scope.model);
        });
        $http.get('v1/teacher').success(function(data){
            $scope.podel = data.result['data'];
             // console.log($scope.podel);
        });

        //清空 提交
        $scope.submit = function(classe){ 

            //选择班级 学校 
             classe.name = $("#sclass option:selected").attr('label');
             classe.school_name = $("#sschool option:selected").attr('label');

            $scope.tem = angular.copy(classe);
             console.log( $scope.tem);
            $http.put('v1/classes/'+ $routeParams.id,$scope.tem).success(function(data){

                if( !data.error ){
                    alert("修改成功","success");
                    window.location.href = '#/classes';
                }else{
                    alert(data.message);
                }
            });
        };

        $scope.reset = function(){
            $scope.tem = {};
            $scope.classe = angular.copy($scope.tem);
        };

        $('.form-date').datetimepicker(
        {
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: 'yyyy-mm-dd'
        });
}]);